package com.tte.common.controller;

import com.tte.common.model.tenum.ResultCode;
import com.tte.common.model.vo.RequestModel;
import com.tte.common.model.vo.ResponseModel;
import com.tte.common.model.vo.ResultBean;
import com.tte.common.jvm.HeapOOM;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("test")
public class TestController {

    /**
     * 测试请求对象：接收带下划线参数
     * @param requestModel
     * @return
     */
    @PostMapping("/requestModel")
    public ResultBean requestModel(@RequestBody RequestModel requestModel){
        return new ResultBean(ResultCode.OK,requestModel);
    }

    /**
     * 测试异常
     * @param
     * @return
     */
    @PostMapping("/error")
    public ResultBean eror(HttpServletRequest request){
        int i = 1/0;
        return new ResultBean(ResultCode.OK,i);
    }

    /**
     * 测试响应对象：更改字段名
     * @Param requestModel
     * @return:
     */
    @PostMapping("/responseModel")
    public ResultBean responseModel(@RequestBody RequestModel requestModel){
        ResponseModel responseModel = new ResponseModel();
        responseModel.setcAddress("广州市");
        responseModel.setcMail("mail163@163.com");
        responseModel.setcPhoneNum("18812345678");
        responseModel.setcName("姓名");
        return new ResultBean(ResultCode.OK,responseModel);
    }

    /**
     * 测试堆内存溢出
     * @return
     */
    @GetMapping("/testHeap")
    public ResultBean testHeap(){
        HeapOOM.testHeap();
        return new ResultBean(ResultCode.OK);
    }

    /**
     * 测试堆内存溢出
     * @return
     */
    @GetMapping("/testStack")
    public ResultBean testStack(){
        HeapOOM.testStack();
        return new ResultBean(ResultCode.OK);
    }

    /**
     * 结束溢出测试
     * @return
     */
    @GetMapping("/endOOM")
    public ResultBean endOOM(){
        HeapOOM.isTrue = false;
        return new ResultBean(ResultCode.OK);
    }

}
